package depth_first_search;

/**
 * author :  apurv verma
 * email  :  dapurv5@gmail.com
 */

import java.util.Comparator;

/*
 * CellComparator DEFINES COMPARISON RELATIONS ON CELLS BASED ON THEIR DISTANCES FROM THE GOAL CELL.
 * A PRIORITYQUEUE UTILIZING THIS COMPARATOR WILL HAVE THE CELL WITH LEAST DISTANCE FROM THE GOAL CELL ON ITS TOP.
 */
public class CellComparator implements Comparator<Dimension>{
	
	int G_x;
	int G_y;
	int G_z;
	
	public CellComparator(Dimension goalLoc){
		G_x=goalLoc.getX();
		G_y=goalLoc.getY();
		G_z=goalLoc.getZ();
	}
	
	public int compare(Dimension u, Dimension v){
		
		int U_x=u.getX();
		int U_y=u.getY();
		int U_z=u.getZ();
		int V_x=v.getX();
		int V_y=v.getY();
		int V_z=v.getZ();
		
		double U=Math.sqrt((U_x-G_x)*(U_x-G_x)+(U_y-G_y)*(U_y-G_y)+(U_z-G_z)*(U_z-G_z));
		double V=Math.sqrt((V_x-G_x)*(V_x-G_x)+(V_y-G_y)*(V_y-G_y)+(U_z-G_z)*(V_z-G_z));
		
		if(U>V)
			{return 1;}
		else if(U<V)
			{return -1;}
		else if(U==V){
			return 0;
		}
		return -2;
	}

}
